package com.usian.controller;

import com.usian.AdNode;
import com.usian.PageResult;
import com.usian.pojo.TbContent;
import com.usian.pojo.TbContentCategory;
import com.usian.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ContentController {

    @Autowired
    private ContentService contentService;

    /***
     * 内容分类管理根据父节点查询子节点
     *
     * @param id
     * @return
     */
    @RequestMapping("selectContentCategoryByParentId")
    public List<TbContentCategory> selectContentCategoryByParentId(@RequestParam Long id) {
        return contentService.selectContentCategoryByParentId(id);
    }

    /**
     *
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("insertContentCategory")
    public Integer insertContentCategory(@RequestParam Long parentId, @RequestParam String name) {
        Integer num = contentService.insertContentCategory(parentId, name);
        return num;
    }

    /**
     * 删除节点
     *
     * @param categoryId
     * @return
     */
    @RequestMapping("deleteContentCategoryById")
    public Integer deleteContentCategoryById(@RequestParam Long categoryId){
        Integer num = contentService.deleteContentCategoryById(categoryId);
        return num;
    }

    /**
     * 根据分类id查询内容列表
     *
     * @param categoryId
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("selectTbContentAllByCategoryId")
    public PageResult selectTbContentAllByCategoryId(@RequestParam Long categoryId,
                                                     @RequestParam Integer page,
                                                     @RequestParam Integer rows){
        return contentService.selectTbContentAllByCategoryId(categoryId,page,rows);
    }


    /**
     * 增加分类内容
     *
     * @param tbContent
     * @return
     */
    @RequestMapping("insertTbContent")
    public  int  insertTbContent(@RequestBody TbContent tbContent){
        return contentService.insertTbContent(tbContent);
    }

    /**
     * 根据id删除内容信息
     *
     * @param ids
     * @return
     */
    @RequestMapping("deleteContentByIds")
    public int deleteContentByIds(@RequestParam Long ids){
        return contentService.deleteContentByIds(ids);
    }


    /**
     * 首页查询大广告位
     *
     * @return
     */
    @RequestMapping("selectFrontendContentByAD")
    public List<AdNode> selectFrontendContentByAD(){
          return contentService.selectFrontendContentByAD();
    }
}
